package com.yumingjiang.service;

import com.yumingjiang.common.model.Result;
import com.yumingjiang.common.model.UserVO;
import com.yumingjiang.common.template.CommonCallback;
import com.yumingjiang.common.template.ServiceOpRedisTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.UUID;

/**
 * @description:
 * @author: John
 * @version: UserServiceImpl.java, v1.0 2024年12月30日 03:53
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private ServiceOpRedisTemplate serviceOpRedisTemplate;

    @Override
    public Result<UserVO> queryById(String id) {
        return serviceOpRedisTemplate.process(id, new CommonCallback() {
            @Override
            public Result doBiz() {
                UserVO userVO = new UserVO();
                userVO.setId(id);
                userVO.setName(Arrays.stream(UUID.randomUUID().toString().split("-")).findFirst().get());

                Result<UserVO> result = new Result<>();
                result.setCode(200);
                result.setMessage("success");
                result.setData(userVO);
                result.setSuccess(true);
                return result;
            }
        });

    }
}